<?php
try{
    include '../ini.php';
    if(empty($_GET['id'])){
        throw new Exception('Mã này không tồn tại');
    }
    $page=isset($_GET['page'])?$_GET['page']:1;
    $start=($page-1)*3;
    $detail_parent=$dt_xl_product->list_parent($_GET['id']);;
    $list_product_detail=$dt_xl_product->list_product_page($start,$_GET['id']);
 
        
        if($list_product_detail == NULL){
            throw new Exception('Xin lỗi hiện tại vẫn chưa có hàng cho quý khách');
        }
        $sum=ceil(count($dt_xl_product->list_product_id($_GET['id']))/3);
        $pagination='';
        if($sum>1){
            $pagination=pagination($page,$sum);
        }
         $dt_smarty->assign('list_product_detail',$list_product_detail);
         $dt_smarty->assign('pagination',$pagination);
    /*}else{
        $list_children=$dt_xl_product->list_children($detail_parent['id']);
        foreach($list_children as $detail_children){
            $list_detail_children=$dt_xl_product->detail_children($detail_children['id']);
            if($list_detail_children != NULL){
                $children[]=$list_detail_children;
            }
        }
        foreach($children as $k=>$v){
            $count=count($v);
        }
        $sum=ceil($count/2);
        $pagination='';
        if($sum>1){
            $pagination=pagination($page,$sum);
        }
        $dt_smarty->assign('children',$children);
        $dt_smarty->assign('pagination_chil',$pagination); 
    }*/
    $dt_smarty->assign('list_product_detail',$list_product_detail);
    $dt_smarty->assign('detail_parent',$detail_parent);
    $contentForLayout=$dt_smarty->fetch('products/list_product.tpl');
    $dt_smarty->assign('titleForLayout',"".$list_product[0]['name']."");
    $dt_smarty->assign('contentForLayout',$contentForLayout);
    $dt_smarty->display('layouts/default.tpl');
}catch(Exception $e){
    $dbh=NULL;
    $_SESSION['msg']=$e->getMessage();
    $_SESSION['type_msg']='error';
    header('Location: /');
}
